﻿using IdentityServer4.EntityFramework.Entities;

namespace Ids4.Api.Application.Profiles
{
    public class ApiResourceProfile : Profile
    {
        public ApiResourceProfile()
        {
            //apiresource
            CreateMap<CreateApiResouceDto, ApiResource>(MemberList.Source).ForMember(x => x.UserClaims, opt => opt.MapFrom(src => src.UserClaims.Select(x => new ApiResourceClaim { Type = x })));
            CreateMap<UpdateApiResourceDto, ApiResource>(MemberList.Source).ForMember(x => x.UserClaims, opt => opt.MapFrom(src => src.UserClaims.Select(x => new ApiResourceClaim { Type = x })));
            CreateMap<ApiResource, ApiResourceVo>(MemberList.Destination).ForMember(x => x.UserClaims, opt => opt.MapFrom(src => src.UserClaims.Select(c => c.Type)));
            CreateMap<ApiResource, ApiResourceListVo>(MemberList.Destination);

            //apiresourcescope
            //CreateMap<ApiResourceScope, ApiResourceScopeListVo>(MemberList.None).ForMember(x => x.UserClaims, opt => opt.MapFrom(src => src.UserClaims.Select(c => c.Type)));
            CreateMap<CreateApiResourceScopeDto, ApiResourceScope>(MemberList.None);
            CreateMap<UpdateApiResourceScopeDto, ApiResourceScope>(MemberList.None);


            //apiresourcesecret
            CreateMap<CreateApiResourceSecretDto, ApiResourceSecret>(MemberList.None);
            CreateMap<CreateApiResourcePropertyDto, ApiResourceProperty>(MemberList.None);
        }
    }
}
